/* Display.h
Copyright (c) 2008 Michael Zahniser
Please note the license terms (MIT license) at the end of this document.

Header file for the Display class, which displays the calculator's stack.
*/

#ifndef __MZ_DISPLAY_H__
#define __MZ_DISPLAY_H__

#include "_sdl/Window.h"

#include "_sdl/Font.h"
#include "Calculator.h"

#include <string>
#include <vector>

using std::string;
using std::vector;



class Display {
public:
	// Initialize the display.
	Display();
	
	// Run the event loop, and wait for a quit event.
	void Run();
	
	
private:
	// Initialize the window and the resources.
	void Initialize();
	
	// Draw the display.
	void Draw();
	// Resize the window, if it does not match the current stack size.
	void UpdateWindow();
	// Draw a transition from one color to another.
	void DrawTransition(int y, bool down, Uint32 from, Uint32 to);
	// Darken the given color.
	Uint32 Darken(Uint32 color, double f);
	
	// Read an entry in the given color array.
	void ReadColor(Uint32 *color);
	void ReadColor(Uint32 &color);
	
	// Function that determines whether or not a given SDL_Event needs to be processed.
	static int EventFilter(const SDL_Event *event);
	
	
private:
	// The window.
	Window window;
	// An object that draws text using glyphs from a bitmap.
	Font stackFont;
	Font entryFont;
	
	// The text the user is currently entering.
	string entry;

	// Object for performing calculations.
	Calculator calculator;


private:
	// Semi-constants.
	Uint32 calculatingColor[3];
	Uint32 programmingColor[3];
	Uint32 definingColor[3];
	
	// Constants.
	static const int WINDOW_WIDTH = 160;
	static const int LINE_HEIGHT = 16;
	static const int MAX_LINES = 32;
};



#endif

/* Copyright (c) 2008 Michael Zahniser

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */
